package com.hz.ruoyilgorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.rouyigonggong.domain.LgDriverLogistics;
import com.hz.rouyigonggong.domain.basedomain.BaseDomain;
import com.hz.rouyigonggong.domain.dto.LgDriverLogisticsDTO;

import com.hz.ruoyilgorder.mapper.LgDriverLogisticsMapper;
import com.hz.ruoyilgorder.mapper.LgDriverMapper;
import com.hz.ruoyilgorder.service.LgDriverLogisticsService;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0
 * @Author yzw
 * @Date 2025/3/6 16:29
 * @注释
 */
@Service
public class LgDriverLogisticsServiceImpl extends ServiceImpl<LgDriverMapper, LgDriverLogistics> implements LgDriverLogisticsService
{

    @Autowired
    private LgDriverLogisticsMapper lgDriverLogisticsMapper;




    @Override
    public List<LgDriverLogisticsDTO> getList(LgDriverLogisticsDTO lgDriverLogistics) {
        return lgDriverLogisticsMapper.getList(lgDriverLogistics);
    }

    @Override
    public LgDriverLogisticsDTO getInfo(Integer id) {
        return lgDriverLogisticsMapper.getInfo(id);
    }


    // 添加 车辆
    @Override
    public int add(LgDriverLogisticsDTO  dto) {

//        if( lgDriverLogisticsMapper.getorder(dto.getLogisticsOrderNumber())==null){
//            //新增
//            return lgDriverLogisticsMapper.insert(dto);
//        }
       if (lgDriverLogisticsMapper.getorder(dto.getLogisticsOrderNumber())!=null){
           //修改
           UpdateWrapper<LgDriverLogisticsDTO> updateWrapper = new UpdateWrapper<>();
           updateWrapper.eq("logistics_order_number",dto.getLogisticsOrderNumber());
           return  lgDriverLogisticsMapper.update(dto, updateWrapper);
        }
        return  0;
    }

    //指派司机
    @Override
    public int adddriver(LgDriverLogisticsDTO dto) {
            //判断是否已经有了车辆
            if( lgDriverLogisticsMapper.getorder(dto.getLogisticsOrderNumber())==null){
                //新增数据
                return lgDriverLogisticsMapper.insert(dto);
            }
        //判断是否已经有了司机
        if( lgDriverLogisticsMapper.getorder(dto.getLogisticsOrderNumber())!=null){
            //修改
            UpdateWrapper<LgDriverLogisticsDTO> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("logistics_order_number",dto.getLogisticsOrderNumber());
            return  lgDriverLogisticsMapper.update(dto, updateWrapper);
        }

        return 0;
    }

    @Override
    public List<LgDriverLogisticsDTO> getnews(Integer driverId) {
        return lgDriverLogisticsMapper.getnews(driverId);
    }

//    @Override
//    public int update(LgDriverLogistics dto) {
//
//
//        //修改
//        UpdateWrapper<LgDriverLogisticsDTO> updateWrapper = new UpdateWrapper<>();
//        updateWrapper.eq("logistics_order_number",dto.getLogisticsOrderNumber());
//        return  lgDriverLogisticsMapper.update(dto, updateWrapper);
//
//        return 0;
//    }

//    @Override
//    public int update(LgDriverLogisticsDTO dto) {
//        //修改
//        UpdateWrapper<LgDriverLogisticsDTO> updateWrapper = new UpdateWrapper<>();
//        updateWrapper.eq("logistics_order_number",dto.getLogisticsOrderNumber());
//        return  lgDriverLogisticsMapper.update(dto, updateWrapper);
//    }
}
